package com.powernode.model;


import com.powernode.constant.BussinessEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("项目统一相应对象")
public class Result<T> implements Serializable {
    @ApiModelProperty("状态码")
    private Integer code=200;
    @ApiModelProperty("消息")
    private String msg = "ok";
    @ApiModelProperty("数据")
    private T data;

    public static <T>Result<T> success(T data) {
        Result result = new Result<>();
        result.setData(data);
        return result;
    }
    public static <T>Result<T> fali(Integer code, String msg) {
        Result result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
    public static <T>Result<T> fali(BussinessEnum bussinessEnum) {
        Result result = new Result();
        result.setCode(bussinessEnum.getCode());
        result.setMsg(bussinessEnum.getMsg());
        result.setData(null);
        return result;
    }
}
